Load local git name/email for cargo init
authorHunter Praska <hunter@wiggin-labs.com>
Tue, 16 May 2017 18:43:22 +0000 (13:43 -0500)
committerHunter Praska <hunter@wiggin-labs.com>
Tue, 16 May 2017 18:43:22 +0000 (13:43 -0500)
Fixes #3920

src/cargo/ops/cargo_new.rs

index 5b4f4faaede9b779adbb072081cbbb5f4189c1e8..1e92aa5c785673688ea3dd41b189726d6c8ce766 100644 (file)
@@ -6,6 +6,7 @@ use std::collections::BTreeMap;
 use rustc_serialize::{Decodable, Decoder};
 
 use git2::Config as GitConfig;
+use git2::Repository as GitRepository;
 
 use term::color::BLACK;
 
@@ -514,7 +515,12 @@ fn get_environment_variable(variables: &[&str] ) -> Option<String>{
 }
 
 fn discover_author() -> CargoResult<(String, Option<String>)> {
-    let git_config = GitConfig::open_default().ok();
+    let cwd = env::current_dir()?;
+    let git_config = if let Ok(repo) = GitRepository::discover(&cwd) {
+        repo.config().ok()
+    } else {
+        GitConfig::open_default().ok()
+    };
     let git_config = git_config.as_ref();
     let name_variables = ["CARGO_NAME", "GIT_AUTHOR_NAME", "GIT_COMMITTER_NAME",
                          "USER", "USERNAME", "NAME"];